package com.liuzy.beauty;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.liuzy.util.Util;

/**
 * http://mnsfz.xiuna.com/
 * 
 * @author liuzy
 * @since 2015年10月26日
 */
public class Mnsfz extends Beauty {
	public static void main(String[] args) {
		new Mnsfz("D:\\beauty\\mnsfz\\", "http://mnsfz.xiuna.com/").start();
	}

	public Mnsfz(String saveDir, String startUrl) {
		super(saveDir, startUrl);
	}

	@Override
	public void search(String url, String html) {
		Matcher matcher = Pattern.compile("href=([\"]{0,1}|[']{0,1})(/h/.*?.html)").matcher(html);
		while (matcher.find()) {
			String path = "http://mnsfz.xiuna.com" + matcher.group(2);
			if (!Util.isHtml(path)) {
				grilQueue.add(path);
			}
		}
		matcher = Pattern.compile("href=([\"]{0,1}|[']{0,1})([a-zA-Z]{16}-\\d.html)").matcher(html);
		while (matcher.find()) {
			String path = url.substring(0, url.lastIndexOf("/") + 1) + matcher.group(2);
			if (!Util.isHtml(path)) {
				grilQueue.add(path);
			}
		}
		matcher = Pattern.compile("http://mnsfz-img.xiuna.com(.*?).jpg").matcher(html);
		while (matcher.find()) {
			String path = "http://mnsfz-img.xiuna.com" + matcher.group(1) + ".jpg";
			path = path.replace("big", "pic");
			if (!Util.isHtml(path)) {
				imageQueue.add(path);
			}
		}
	}

	@Override
	public String reName(String url) {
		return url.substring(url.indexOf("pic/") + 4).replaceAll("/", ".");
	}

}
